package com.css.filexml.client;

import com.alibaba.fastjson.JSON;
import com.css.filexml.model.MsgEntity;
import org.springframework.integration.ip.udp.UnicastSendingMessageHandler;
import org.springframework.integration.support.MessageBuilder;

/**
 * 客户端
 *
 * @author 一朝风月
 * @date 2021/12/16 20:06
 */
public class FileXmlClient {
    private String host;
    private Integer port;

    public FileXmlClient(String host, Integer port) {
        this.host = host;
        this.port = port;
    }

    public void send(MsgEntity sendMsg) {
        UnicastSendingMessageHandler handler =
                new UnicastSendingMessageHandler(host, port);

        String payload = JSON.toJSONString(sendMsg);
        handler.handleMessage(MessageBuilder.withPayload(payload).build());
    }
}
